package com.tencent.stat.common;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Matrix;
import android.util.Log;
import java.io.File;

public class g
{
  private static int a(int paramInt1, int paramInt2)
  {
    if (paramInt1 < paramInt2)
      return paramInt1;
    return paramInt2;
  }

  private static int a(BitmapFactory.Options paramOptions, int paramInt)
  {
    int i = paramOptions.outHeight;
    int j = paramOptions.outWidth;
    if (j > i);
    for (paramInt = (int)Math.floor(i / paramInt); ; paramInt = (int)Math.floor(j / paramInt))
    {
      i = paramInt / 2 * 2;
      paramInt = i;
      if (i <= 0)
        paramInt = 0;
      return paramInt;
    }
  }

  private static Bitmap a(Bitmap paramBitmap)
  {
    if (paramBitmap == null)
      return null;
    Matrix localMatrix = new Matrix();
    float f = 240.0F / a(paramBitmap.getWidth(), paramBitmap.getHeight());
    localMatrix.postScale(f, f);
    return Bitmap.createBitmap(paramBitmap, 0, 0, paramBitmap.getWidth(), paramBitmap.getHeight(), localMatrix, true);
  }

  private static Bitmap a(String paramString, int paramInt)
  {
    try
    {
      Object localObject = new BitmapFactory.Options();
      ((BitmapFactory.Options)localObject).inJustDecodeBounds = true;
      BitmapFactory.decodeFile(paramString, (BitmapFactory.Options)localObject);
      if ((((BitmapFactory.Options)localObject).mCancel) || (((BitmapFactory.Options)localObject).outWidth == -1))
        break label125;
      if (((BitmapFactory.Options)localObject).outHeight == -1)
        break label125;
      ((BitmapFactory.Options)localObject).inSampleSize = a((BitmapFactory.Options)localObject, paramInt);
      ((BitmapFactory.Options)localObject).inJustDecodeBounds = false;
      ((BitmapFactory.Options)localObject).inDither = false;
      ((BitmapFactory.Options)localObject).inPreferredConfig = Bitmap.Config.RGB_565;
      Bitmap localBitmap = BitmapFactory.decodeFile(paramString, (BitmapFactory.Options)localObject);
      localObject = a(localBitmap);
      paramString = (String)localObject;
      if (localBitmap == null)
        break label127;
      paramString = (String)localObject;
      if (localBitmap.isRecycled())
        break label127;
      localBitmap.recycle();
      return localObject;
    }
    catch (java.lang.OutOfMemoryError paramString)
    {
      Log.e("ScreenShot", "Got oom exception ", paramString);
      System.gc();
      return null;
    }
    catch (Throwable paramString)
    {
      paramString.printStackTrace();
      return null;
    }
    label125: paramString = null;
    label127: return ((Bitmap)paramString);
  }

  // ERROR //
  private static void a(Bitmap paramBitmap, File paramFile)
  {
    // Byte code:
    //   0: aload_0
    //   1: ifnonnull +4 -> 5
    //   4: return
    //   5: ldc 120
    //   7: aload_1
    //   8: invokevirtual 126	java/io/File:toString	()Ljava/lang/String;
    //   11: invokestatic 129	android/util/Log:e	(Ljava/lang/String;Ljava/lang/String;)I
    //   14: pop
    //   15: new 131	java/io/FileOutputStream
    //   18: dup
    //   19: aload_1
    //   20: invokespecial 134	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   23: astore_2
    //   24: aload_2
    //   25: astore_1
    //   26: aload_0
    //   27: getstatic 140	android/graphics/Bitmap$CompressFormat:PNG	Landroid/graphics/Bitmap$CompressFormat;
    //   30: bipush 75
    //   32: aload_2
    //   33: invokevirtual 144	android/graphics/Bitmap:compress	(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z
    //   36: pop
    //   37: aload_2
    //   38: astore_1
    //   39: aload_2
    //   40: invokevirtual 147	java/io/FileOutputStream:flush	()V
    //   43: aload_2
    //   44: invokevirtual 150	java/io/FileOutputStream:close	()V
    //   47: aload_0
    //   48: invokevirtual 92	android/graphics/Bitmap:isRecycled	()Z
    //   51: ifne -47 -> 4
    //   54: aload_0
    //   55: invokevirtual 95	android/graphics/Bitmap:recycle	()V
    //   58: return
    //   59: astore_0
    //   60: aload_0
    //   61: invokevirtual 151	java/io/IOException:printStackTrace	()V
    //   64: return
    //   65: astore_3
    //   66: aconst_null
    //   67: astore_2
    //   68: aload_2
    //   69: astore_1
    //   70: aload_3
    //   71: invokevirtual 152	java/io/FileNotFoundException:printStackTrace	()V
    //   74: aload_2
    //   75: ifnull +7 -> 82
    //   78: aload_2
    //   79: invokevirtual 150	java/io/FileOutputStream:close	()V
    //   82: aload_0
    //   83: invokevirtual 92	android/graphics/Bitmap:isRecycled	()Z
    //   86: ifne -82 -> 4
    //   89: aload_0
    //   90: invokevirtual 95	android/graphics/Bitmap:recycle	()V
    //   93: return
    //   94: astore_0
    //   95: aload_0
    //   96: invokevirtual 151	java/io/IOException:printStackTrace	()V
    //   99: return
    //   100: astore_3
    //   101: aconst_null
    //   102: astore_2
    //   103: aload_2
    //   104: astore_1
    //   105: aload_3
    //   106: invokevirtual 151	java/io/IOException:printStackTrace	()V
    //   109: aload_2
    //   110: ifnull +7 -> 117
    //   113: aload_2
    //   114: invokevirtual 150	java/io/FileOutputStream:close	()V
    //   117: aload_0
    //   118: invokevirtual 92	android/graphics/Bitmap:isRecycled	()Z
    //   121: ifne -117 -> 4
    //   124: aload_0
    //   125: invokevirtual 95	android/graphics/Bitmap:recycle	()V
    //   128: return
    //   129: astore_0
    //   130: aload_0
    //   131: invokevirtual 151	java/io/IOException:printStackTrace	()V
    //   134: return
    //   135: astore_2
    //   136: aconst_null
    //   137: astore_1
    //   138: aload_1
    //   139: ifnull +7 -> 146
    //   142: aload_1
    //   143: invokevirtual 150	java/io/FileOutputStream:close	()V
    //   146: aload_0
    //   147: invokevirtual 92	android/graphics/Bitmap:isRecycled	()Z
    //   150: ifne +7 -> 157
    //   153: aload_0
    //   154: invokevirtual 95	android/graphics/Bitmap:recycle	()V
    //   157: aload_2
    //   158: athrow
    //   159: astore_0
    //   160: aload_0
    //   161: invokevirtual 151	java/io/IOException:printStackTrace	()V
    //   164: goto -7 -> 157
    //   167: astore_2
    //   168: goto -30 -> 138
    //   171: astore_3
    //   172: goto -69 -> 103
    //   175: astore_3
    //   176: goto -108 -> 68
    //
    // Exception table:
    //   from	to	target	type
    //   43	58	59	java/io/IOException
    //   15	24	65	java/io/FileNotFoundException
    //   78	82	94	java/io/IOException
    //   82	93	94	java/io/IOException
    //   15	24	100	java/io/IOException
    //   113	117	129	java/io/IOException
    //   117	128	129	java/io/IOException
    //   15	24	135	finally
    //   142	146	159	java/io/IOException
    //   146	157	159	java/io/IOException
    //   26	37	167	finally
    //   39	43	167	finally
    //   70	74	167	finally
    //   105	109	167	finally
    //   26	37	171	java/io/IOException
    //   39	43	171	java/io/IOException
    //   26	37	175	java/io/FileNotFoundException
    //   39	43	175	java/io/FileNotFoundException
  }

  public static void a(String paramString, File paramFile)
  {
    a(a(paramString, 240), paramFile);
  }
}